package com.itheima.app.controller;

import cn.hutool.core.date.DateUtil;
import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    MakeFriendManager makeFriendManager;

    //今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest(){
        return makeFriendManager.findTodayBest();
    }

    //推荐用户分页查询
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        return makeFriendManager.findRecommendUserByPage(pageNum,pageSize);
    }

    //查询推荐用户详情
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long recommendUserId){
        return makeFriendManager.findPersonalInfo(recommendUserId);
    }

    //判断是否已经喜欢当前用户
    @GetMapping("/users/{recommendUserId}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable Long recommendUserId){
        //TODO 等我们后天过后就可以自己去完成  查询 like表
        return ResponseEntity.ok(false);
    }

    //最近访客
    @GetMapping("/movements/visitors")
    public ResponseEntity findVisitorsTop5(){
        return makeFriendManager.findVisitorsTop5();
    }

    //上报地址位置
    @PostMapping("/baidu/location")
    public void saveUserLocation(@RequestBody Map<String,String> map){
        System.out.println(DateUtil.formatDateTime(new Date())+"用户上报位置:"+ map);

        //1.获取参数
        Double longitude = Double.parseDouble(map.get("longitude"));
        Double latitude = Double.parseDouble(map.get("latitude"));
        String addrStr = map.get("addrStr");

        //2.调用manager完成操作
        makeFriendManager.saveUserLocation(longitude,latitude,addrStr);
    }

    //搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNear(String gender,Long distance){
        return makeFriendManager.searchNear(gender, distance);
    }

    //查看陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestion(Long userId){
       return makeFriendManager.findStrangerQuestion(userId);
    }

}
